var Calculate=function(sequence,index, index1,splice = 0,value = '') {
	
	if(sequence.length >0){
		var  type =  -1;
		for(var i= 0 ; i < sequence.length;i++){
			if(sequence[i]['index']  == index &&  sequence[i]['index1']  == index1) {
				type  = i;
			}
		}
		if(type  > -1){
			if(splice == 0 ) sequence.splice(type,1);
			sequence.push({
				'index' : index,
				'index1': index1,
				'value' : value
			})
		}else{
			sequence.push({
				'index' : index,
				'index1': index1,
				'value' : value
			})
		}
		
	}else{
		console.log(sequence);
		sequence.push({
			'index' : index,
			'index1': index1,
			'value' : value
		})
	}
	return sequence;
}


var numSub =function(num1, num2) {
	var baseNum, baseNum1, baseNum2;
	var precision;// 精度
	try {
		baseNum1 = num1.toString().split(".")[1].length;
	} catch (e) {
		baseNum1 = 0;
	}
	try {
		baseNum2 = num2.toString().split(".")[1].length;
	} catch (e) {
		baseNum2 = 0;
	}
	baseNum = Math.pow(10, Math.max(baseNum1, baseNum2));
	precision = (baseNum1 >= baseNum2) ? baseNum1 : baseNum2;
	return ((num1 * baseNum - num2 * baseNum) / baseNum).toFixed(precision);
}


var cachequestions = function(query,questions,id,timer,keys){
	var value = {
		'query' : query,
		'questions':questions,
		'id'      : id,
		'timer'   : timer
	};
	return uni.setStorageSync(keys,JSON.stringify(value));
	
}
module.exports = {
	Calculate,numSub,cachequestions
}